package config;


import org.dom4j.DocumentException;

import xmlRW.ReadXml;
public class DB {
	public String DBConfigPath;
	
	public DB(){
		ConfigFilePath cfp = new ConfigFilePath();
		DBConfigPath = cfp.getDBConfigPath();
	}
	
	@SuppressWarnings("static-access")
	public String getDBDriver(){
		String res ="";		
		try {
			ReadXml rxm = new ReadXml(DBConfigPath);
			res = rxm.getAttributes("/DBS/DB[@type=\"mysql\"]/driver");
		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}		
		return res;
	}
	
	@SuppressWarnings("static-access")
	public String getDBIp(){	
		String res ="";		
		try {
			ReadXml rxm = new ReadXml(DBConfigPath);
			res = rxm.getAttributes("/DBS/DB[@type=\"mysql\"]/ip");
		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}		
		return res;
	}
	
	@SuppressWarnings("static-access")
	public String getDBPort(){
		String res ="";		
		try {
			ReadXml rxm = new ReadXml(DBConfigPath);
			res = rxm.getAttributes("/DBS/DB[@type=\"mysql\"]/port");
		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}	
		return res;
	}
	
	@SuppressWarnings("static-access")
	public String getDBName(){
		String res ="";		
		try {
			ReadXml rxm = new ReadXml(DBConfigPath);
			res = rxm.getAttributes("/DBS/DB[@type=\"mysql\"]/dbname");
		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}	
		return res;
	}
	
	@SuppressWarnings("static-access")
	public String getDBCharcode(){
		String res ="";		
		try {
			ReadXml rxm = new ReadXml(DBConfigPath);
			res = rxm.getAttributes("/DBS/DB[@type=\"mysql\"]/charcode");
		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return res;
	}
	
	@SuppressWarnings("static-access")
	public String getDBUser(){
		String res ="";		
		try {
			ReadXml rxm = new ReadXml(DBConfigPath);
			res = rxm.getAttributes("/DBS/DB[@type=\"mysql\"]/dbuser");
		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return res;
	}
	
	@SuppressWarnings("static-access")
	public String getDBUserCode(){
		String res ="";		
		try {
			ReadXml rxm = new ReadXml(DBConfigPath);
			res = rxm.getAttributes("/DBS/DB[@type=\"mysql\"]/dbuser/@passwd");
		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return res;
	}
	
	

}
